package com.ssh;

import org.junit.Test;

public class SearchInsert_35 {
	public int searchInsert(int[] nums, int target) {
        int a = b(nums,0,nums.length-1,target);
        return a;
    }
	public int b (int[] nums, int l, int r, int target) {
		if (r < l) {
			return l;
		}
		System.out.println("r="+r);
		System.out.println("l="+l);
		int mid = l + (r - l) / 2;
		if (nums[mid] < target) {
			return b (nums, mid+1, r, target);
		}else if (nums[mid] > target) {
			return b (nums, l, mid-1, target);
		}else {
			return mid;
		}
	}
	@Test
	public void test () {
		int[] nums = {1,3,5,6};
		System.out.println(searchInsert(nums, 7));
	}
}
